﻿//written by Gareth Kenny, for use in cp2013
//Licenced under GNU GPL version 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;



namespace assingment1_rowan_Hall
{
    public struct dot
    {
        public int x;
        public int y;
        public int radius;
    }
    class Elevator
    {
        private int destination;
        private int floor;
        private int top;
        private int bottom;
        private int Defaultfloor;
        private int floorDiff;
        public bool doorsOpen = false;
        public dot location;
        public Elevator(int floor = 0, int top = 0, int bottom = 0, int Defaultfloor = 0)
        {
            if (!(floor > top) && !(floor < bottom))
                this.floor = floor;
            if (!(top < bottom))
                this.top = top;
            if (!(bottom > top))
                this.bottom = bottom;
            if (Defaultfloor > bottom && Defaultfloor < top)
                this.Defaultfloor = Defaultfloor;
            this.location.x = 0;
            this.location.y = 0;
            this.location.radius = 10;
            this.doorsOpen = true;
        }
        public void setDestination(int x)
        {
            this.destination = x;
        }

        public int GetFloor()
        {
            var a = this.floor;
            return a;
        }
        public int mutateFloor(int newFloor)
        {
            if (newFloor > this.bottom && newFloor < this.top)
            {
                this.floor = newFloor;
                this.location.y = newFloor * 10;
                return 0;
            }
            else
                return -1;
        }
        public int mutateTop(int newTop)
        {
            if (newTop > this.bottom)
            {
                this.top = newTop;
                if (floor > top && this.Defaultfloor > top)
                    floor = top;
                else if (floor > top)
                    floor = Defaultfloor;

                return 0;
            }
            else
                return -1;
        }
        public int mutateBottom(int newbottom)
        {
            if (newbottom < this.top)
            {
                this.bottom = newbottom;
                if (floor < bottom && this.Defaultfloor < bottom)
                    floor = bottom;
                else if (floor < bottom)
                    floor = Defaultfloor;
                return 0;
            }
            else
                return -1;
        }
        public int mutateDefault(int newDefault)
        {
            if (newDefault > this.bottom && newDefault < this.top)
            {
                this.Defaultfloor = newDefault;
                return 0;
            }
            else
                return -1;
        }
        public int mutateFloorDiff(int Diff)
        {
            if (Math.Abs(Diff) < (top - floor) || Math.Abs(Diff) < (floor - bottom))//ok, when i wrote this it made a lot of sense, looking back on it, it makes none
            {
                this.floorDiff = Diff;
                return 0;
            }
            else
                return -1;
        }
        public int viewFloor()
        {
            return this.floor;
        }
        public int viewTop()
        {
            return this.top;
        }
        public int viewBottom()
        {
            return this.bottom;
        }
        public int viewDefault()
        {
            return this.Defaultfloor;
        }
        public int viewFloorDiff()
        {
            return this.floorDiff;
        }
        public int callToFloor(int callingFloor)
        {
            if (callingFloor <= this.top && callingFloor >= this.bottom)
            {
                floorDiff = floor - callingFloor;
                floor = callingFloor;
                return floorDiff;
            }
            else
                return -1000;
        }//note: these funtions will just change the numbers the graphical transition will be handled be the ui code, they will however return a difference of the start and ending floors that the ui can use, negitive for down, positive for up, 0 for the same floor.
        public int goToFloor(int finalFloor)
        {
            if (finalFloor <= this.top && finalFloor >= this.bottom)
            {
                floorDiff = finalFloor - floor;
                floor = finalFloor;
                return floorDiff;
            }
            else
                return -1000;
        }
        public int move(int moveDist = 10)
        {
            if (this.floorDiff != 0)
            {
                this.doorsOpen = false;
                if (this.floorDiff < 0)
                {
                    this.location.y -= moveDist;
                    this.floorDiff += 1;
                    return -1;
                }
                else if (this.floorDiff > 0)
                {
                    this.location.y += moveDist;
                    this.floorDiff -= 1;
                    return 1;
                }
            }
            else
            {
                this.doorsOpen = true;
                return 0;
            }
            return -2;
        }
        public int drawLoc(Graphics g, Pen b, bool open)
        {
            if (open == true)
                g.DrawEllipse(b, this.location.x, this.location.y, this.location.radius, this.location.radius);
            else
                g.FillEllipse(b.Brush, this.location.x, this.location.y, this.location.radius, this.location.radius);
            return 0;
        }
    }

}

